import uuid
from django.db import models
from django.contrib.auth import get_user_model

from movie.models import MoviePieceSeat

User = get_user_model()


# Create your models here.
class MovieOrders(models.Model):
    """
    用户流水订单号信息
    """

    user = models.ForeignKey(User, verbose_name='创建订单的用户', help_text='创建订单的用户')
    tmp_order_num = models.UUIDField(default=uuid.uuid4, editable=False, verbose_name='流水号', help_text='流水号')
    add_time = models.DateTimeField(auto_now_add=True, verbose_name='订单添加时间', help_text='订单添加时间')
    plat_order_num = models.CharField(max_length=100, verbose_name='平台返回的订单号')
    fininsh_time = models.DateTimeField(null=True, default=None, verbose_name='完成支付时间')
    post_amount = models.FloatField(null=True, default=None, verbose_name='实际支付的金额', help_text='实际支付的金额')
    order_amount = models.FloatField(verbose_name='需要支付的金额', help_text='需要支付的金额')

    order_seats = models.ManyToManyField(MoviePieceSeat,verbose_name='订单所订购的座位')

    class Meta:
        verbose_name = '流水订单'
        verbose_name_plural = verbose_name

    def __str__(self):
        return str('用户:{},订单{}'.format(self.user.username, self.tmp_order_num))
